/*
 * InputProviderModel.java
 *
 * Stateroom - Java framework library for finite state machines
 * Copyright (C) 2009 by Matthew Werny
 * All Rights Reserved
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
package net.iceflow.stateroom.models;

import net.iceflow.stateroom.interfaces.InputProvider;
import net.iceflow.stateroom.interfaces.Model;
import net.iceflow.stateroom.Utility;

/**
 * Machine model that uses an input provider to determine whether the machine has a necessary condition to stop operation.
 * @param <T> Type used to represent the input alphabet for the input provider
 */
public class InputProviderModel<T> implements Model {

   /** Input provider from which to get input objects. */
   private final InputProvider<T> _provider;

   /**
    * Constructs a new InputProviderModel using the provided InputProvider.
    * @param provider Provider instance to use in the model
    */
   public InputProviderModel(InputProvider<T> provider) {
      // Validate the argument to make sure it is not null.
      Utility.validateNotNull(provider, "provider may not be null.");

      // Define the finalized provider based on the parameter
      this._provider = provider;
   }

   /**
    * Indicates whether there is a sufficient condition for stopping the operation of the machine.
    * @return truth of whether an end condition exists
    */
   @Override
   public boolean isEnd() {
      // Assume that there is no need to end, unless it can be determined otherwise
      boolean truthOfEnd = false;

      // If no further input is available
      if (this._provider.isInputAvailable() == false) {

         // Indicate that there is a reason to end
         truthOfEnd = true;
      }

      // Return the determination that was made
      return truthOfEnd;
   }

   /**
    * Getter for the provider.
    * @return the provider of the series of input values
    */
   public InputProvider<T> getProvider() {
      // Return the instance of the input provider
      return this._provider;
   }
}
